package com.piesat.feaedit.feaedit.base.response.handler;

import com.piesat.feaedit.feaedit.base.exception.BusinessException;
import com.piesat.feaedit.feaedit.base.exception.ResponseTimeoutException;
import com.piesat.feaedit.feaedit.base.response.BaseResponse;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
public class BusinessExceptionHandler {

    @ResponseBody
    @ExceptionHandler(BusinessException.class)
    @ResponseStatus(value = HttpStatus.BAD_REQUEST)
    public Object handleValidException(BusinessException e) {
        return BaseResponse.failure(400, e.getMessage());
    }


    @ResponseBody
    @ExceptionHandler(ResponseTimeoutException.class)
    @ResponseStatus(value = HttpStatus.GATEWAY_TIMEOUT)
    public Object handleTimeoutException(ResponseTimeoutException e) {
        return BaseResponse.failure(HttpStatus.GATEWAY_TIMEOUT.value(), e.getMessage());
    }



}
